package com.itheima.demo01;

public class Person {
    // 人的类
    private String name;// 姓名
    private int age;// 年龄

    public Person() {

    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /*   public void keepPet(Dog dog, String something) {
           System.out.println("年龄为" + age + "岁的" + name + "养了一只" + dog.getColor() + "颜色的" + dog.getAge() + "岁的狗");
           dog.eat(something);
       }

       public void keepPet(Cat cat, String something) {
           System.out.println("年龄为" + age + "岁的" + name + "养了一只" + cat.getColor() + "颜色的" + cat.getAge() + "岁的猫");
           cat.eat(something);
       }*/
    public void keepPet(Animal a, String something) {
        if (a instanceof Dog) {
            Dog d = new Dog();
            System.out.println("年龄为" + age + "岁的" + name + "养了一只" + a.getColor() + "颜色的" + a.getAge() + "岁的狗");
            a.eat(something);
            d.lookHome();
        } else if (a instanceof Cat) {
            Cat c = new Cat();
            System.out.println("年龄为" + age + "岁的" + name + "养了一只" + a.getColor() + "颜色的" + a.getAge() + "岁的猫");
            a.eat(something);
            c.catchMice();
        }else {
            System.out.println("没有这个动物");
        }
    }
}
